class GameBegin extends eui.Component implements  eui.UIComponent {

	// 游戏开始按钮
	public btnBegin:eui.Button;
	// 设置按钮
	public btnSetting:eui.Button;
	
	// 声明单例
	private static shared: GameBegin;
	public static Shared(): GameBegin{
		if(GameBegin.shared == null) {
			GameBegin.shared = new GameBegin();
		}
		return GameBegin.shared;
	}
	
	public constructor() {
		super();
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}


	protected childrenCreated():void
	{
		super.childrenCreated();
		this.init();
	}
	

	// 初始化
	private init() {

		// 给两个按钮绑定点击方法
		this.btnSetting.addEventListener(
			egret.TouchEvent.TOUCH_TAP,
			this.settingTap,
			this
		);

		this.btnBegin.addEventListener(
			egret.TouchEvent.TOUCH_TAP,
			this.beginTap,
			this
		);

		// 设置游戏背景音乐默认是可播放
		SoundManager.Shared().isMusic = true;
	}

	/**
	 * 点按设置按钮的响应函数
	 */
	private settingTap() {
		// 打开设置界面
		// console.log("打开设置界面");
		SoundManager.Shared().playClick();
		this.addChild(GameSetting.Shared());
	}

	/**
	 * 点按开始按钮的响应函数
	 */
	private beginTap() {
		// 点击开始按钮音效
		SoundManager.Shared().playClick();

		// 打开游戏关卡界面
		console.log("打开游戏关卡界面");

		// 把游戏关卡场景添加到显示列表
		this.parent.addChild(SceneLevel.Shared());
		// 移除游戏开始场景
		this.parent.removeChild(this);
	}

}